import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

import Layout from '@/layout'

// 公共路由
const constantRoutes = [{
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    meta: {
      title: 'Nav',
      icon: 'Nav'
    },
    children: [{
      name: 'Dashboard',
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: {
        title: 'Dashboard',
        icon: 'dashboard'
      },
    }],
  },
  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    meta: {
      title: 'Example',
      icon: 'Example'
    },
    children: [{
        name: 'Table',
        path: 'table',
        component: () => import('@/views/table/index'),
        meta: {
          title: 'Table',
          icon: 'table'
        }
      },
      {
        name: 'Tree',
        path: 'tree',
        component: () => import('@/views/tree/index'),
        meta: {
          title: 'Tree',
          icon: 'tree'
        }
      }
    ]
  },
  {
    path: '/form',
    component: Layout,
    children:[{
      name: 'From',
      path: 'index',
      component: () => import('@/views/form/index'),
      meta: {
        title: 'index',
        icon: 'index'
      }
    }]
  }

]

// 权限路由
export const asyncRoutes = []

// 实例化新路由
const createRouter = () => new VueRouter({
  scrollBehavior: () => ({
    y: 0
  }), // 设置路由跳转后滚动条在顶部
  routes: constantRoutes
})

const router = createRouter()

// 替换路由
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
